<template>
  <div style="background-color: #ececec">
    <router-view v-if="isRouterAlive" />
  </div>

</template>

<script setup>

import {nextTick, onBeforeMount, provide, ref} from "vue";
import {store} from "@/store";

const isRouterAlive = ref(true);

onBeforeMount( () => {
    // 在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("rsms-store")) {

        store.state= JSON.parse(sessionStorage.getItem("rsms-store"))
        sessionStorage.removeItem("rsms-store");
    }else
        store.state={
            selectMenu:"/goods",
            waiting:[]
        }


    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
        sessionStorage.setItem("rsms-store", JSON.stringify(store.state))
    })
})

const reload = () => {
  setTimeout(()=>{
    isRouterAlive.value = false;
    nextTick(() => {
      isRouterAlive.value = true;
    });
  },300)

};
provide("reload", reload);

</script>

<style>

</style>
